<template>
    <div class="geo-location">
        <input type="search" name="" id="city" v-model="search" placeholder="请输入城市的名字(中文或拼音)" @change="getData()">
    </div>
</template>
<script>
import axios from 'axios'
import {KEY, API_LOCATION} from "@/common/constrants";
import {mapActions } from 'vuex';
export default {
    data(){
        return{
            search:""
        }
    },
    methods:{
        ...mapActions([
            "updateLocationAction"
        ]),
        getData(){
            axios.get(API_LOCATION,{
        params:{
          key:KEY,
          location:this.search,//等价于this.$store.state.location.id
          
        }
        }).then(res => {
            // console.log(res.data);
            this.updateLocationAction(res.data.location[0])
            // console.log(this.$store.state.location)
            })
        }
    }
}
</script>

<style scoped>

</style>